<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="custom" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <title>部门列表</title>
</head>

<body>
<div class="pageheader">
    <c:if test="${ empty listDto.parentDeptDto}">
        <h2>部门列表</h2>
    </c:if>
    <c:if test="${not empty listDto.parentDeptDto}">
        <h2>${listDto.parentDeptDto.name}</h2>
    </c:if>
</div>
<div class="contentpanel">
    <form class="form-inline">
        <input type="hidden" name="parent_uuid" value="${listDto.parent_uuid}">

        <div class="btn-group mr10">
            <input type="text" class="form-control " name="name" value="${listDto.name}"
                   placeholder="请输入要查询的部门">
            <button type="submit" class="form-control btn-success">查询</button>
        </div>
        <div class="btn-group mr10">
            <c:if test="${not empty listDto.parentDeptDto}">
                <a href="${contextPath}/admin/organization/dept/list.htm?parent_uuid=${listDto.parentDeptDto.parentUuid}"
                   class="btn btn-info" type="button">
                    <i class="fa fa-backward mr5"></i>返回上级
                </a>
            </c:if>

            <a href="${contextPath}/admin/organization/dept/edit.htm?parent_uuid=${listDto.parent_uuid}"
               class="btn btn-primary"
               type="button">
                <i class="fa fa-pencil mr5"></i>添加部门
            </a>
        </div>
        <shiro:hasPermission name="ORGANIZATION_ACCOUNT_LIST:*">
            <div class="btn-group mr10">
                <a href="${contextPath}/admin/organization/account/list.htm?deptUuid=${listDto.parent_uuid}"
                   class="btn btn-darkblue" type="button">
                    账号列表
                </a>
            </div>
        </shiro:hasPermission>
    </form>

    <table class="table table-striped dataTable no-footer" id="table2" role="grid" aria-describedby="table2_info">
        <thead>
        <tr role="row">
            <th class="sorting_asc" tabindex="0" aria-controls="table2"
                rowspan="1" colspan="1" aria-sort="ascending">
                部门名称
            </th>
            <th class="sorting_asc" tabindex="0" aria-controls="table2"
                rowspan="1" colspan="1" aria-sort="ascending">
                创建时间
            </th>
            <th class="sorting" tabindex="0" aria-controls="table2" rowspan="1" colspan="1">
                操作
            </th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${listDto.list}" var="item" varStatus="status">
            <tr class="gradeA ${status.index/2 eq 0?"odd":"even"}">
                <td>
                        ${item.name}
                </td>
                <td>
                    <span class="label label-default">${item.createDateTime}</span>
                </td>
                <td>
                    <div class="form-group">
                        <form class="form-inline col-sm-9" action="${contextPath}/admin/organization/dept/delete.htm"
                              method="post">

                            <a class="btn btn-info"
                               href="${contextPath}/admin/organization/dept/list.htm?parent_uuid=${item.uuid}">下级部门</a>

                            <shiro:hasPermission name="ORGANIZATION_EMPLOYEE_LIST:*">
                                <a class="btn btn-primary"
                                   href="${contextPath}/admin/organization/employee/list.htm?deptUuid=${item.uuid}">员工列表</a>
                            </shiro:hasPermission>

                            <shiro:hasPermission name="ORGANIZATION_ACCOUNT_LIST:*">
                                <a class="btn btn-darkblue"
                                   href="${contextPath}/admin/organization/account/list.htm?deptUuid=${item.uuid}">账号列表</a>
                            </shiro:hasPermission>

                            <a class="btn btn-warning"
                               href="${contextPath}/admin/organization/dept/edit.htm?uuid=${item.uuid}&parent_uuid=${listDto.parent_uuid}">编辑</a>
                            <input type="hidden" name="uuid" value="${item.uuid}">
                            <input type="hidden" name="parent_uuid" value="${item.parentUuid}">
                            <button class="btn btn-danger" type="submit"
                                    onclick="javascript:return confirm('确定删除部门[${item.name}]和它的子部门吗?');">
                                删除
                            </button>
                        </form>
                    </div>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <custom:page page="${listDto}"/>
    <c:if test="${not empty param.edit}">
        <script type="text/javascript">
            jQuery.gritter.add({
                title: '新增/编辑 成功!',
                class_name: "growl-success",
                sticky: false
            });
        </script>
    </c:if>
    <c:if test="${not empty param.delete}">
        <script type="text/javascript">
            jQuery.gritter.add({
                title: '删除 成功!',
                class_name: "growl-success",
                sticky: false
            });
        </script>
    </c:if>
</div>
<script src="${contextPath}/resources/js/jquery.datatables.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('#table2').dataTable({
            "bPaginate": false,// 分页按钮
            "bFilter": false,// 搜索栏
            "bLengthChange": false,// 每行显示记录数
            "bInfo": false
        });
    });
</script>
</body>
</html>
